<?php

class PerfilController extends BaseController {

	/*
	|--------------------------------------------------------------------------
	| Default Home Controller
	|--------------------------------------------------------------------------
	|
	| You may wish to use controllers instead of, or in addition to, Closure
	| based routes. That's great! Here is an example controller method to
	| get you started. To route to this controller, just add the route:
	|
	|	Route::get('/', 'HomeController@showWelcome');
	|
	*/

	public function index()
	{
		$user= Auth::user();
		return View::make('contents.perfil', compact('user'));
	}
	
	public function show($id){
		$user= User::find($id);
		return View::make('contents.perfiluser', compact('user'));
	}
	
	public function update($id){
		$user = User::findOrFail($id);
		
		if(Input::get('password')==''){
			$inputs=Input::except('password');
		}else{
			$inputs=Input::all();
		}
		
		$validator = Validator::make($data = $inputs, User::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}
		
		$user->update($data);
		if(isset($inputs['password'])){
			$user->password=Hash::make($user->password);
			$user->save();
		}
		return Redirect::route('perfil');
	}

}